package com.nineclock.doc.service.impl;

import com.nineclock.common.enums.ResponseEnum;
import com.nineclock.common.exception.NcException;
import com.nineclock.common.threadlocal.CurrentUserHolder;
import com.nineclock.common.utils.BeanHelper;
import com.nineclock.doc.dto.DocFileDto;
import com.nineclock.doc.mapper.DocFileDtoMapper;
import com.nineclock.doc.pojo.DocFile;
import com.nineclock.doc.service.StatusService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
@Slf4j
public class StatusServiceImpl implements StatusService {
    @Autowired
    DocFileDtoMapper docFileDtoMapper;

    @Override
    public void StatusController(Long fileId, Short status) {
        //健壮性判断id,和状态
        if (fileId == null || status == null) {
            throw new NcException(ResponseEnum.UPDATE_OPERATION_FAIL);
        }
        DocFile docFile = docFileDtoMapper.selectById(fileId);

        if (docFile != null) {
            docFile.setStatus(status);
            docFileDtoMapper.updateById(docFile);

        }
    }





    @Override
    public void deleteFiles(Long id) {
        DocFile docFile = docFileDtoMapper.selectById(id);
        if (docFile != null) {
            docFileDtoMapper.deleteById(docFile);
        }
    }

    @Override
    public void updateFile(DocFileDto docFileDto) {
        DocFile docFile = BeanHelper.copyProperties(docFileDto, DocFile.class);
        System.out.println(docFile);
        System.out.println(docFile);
        System.out.println(docFile);
        System.out.println(docFile);
        if (docFileDto == null){
            throw  new NcException(ResponseEnum.INVALID_PARAM_ERROR);
        }


    }


}
